﻿namespace Yaaf.WP7.NativeAccess.IO.Internals.HTC.COM_NativeAccess
{
    using System;
    using System.IO;

    internal class FileStream : Stream
    {
        private File file;

        internal FileStream(File file)
        {
            this.file = file;
        }

        public override void Close()
        {
            this.file.Close();
            base.Close();
        }

        public override void Flush()
        {
            throw new NotImplementedException();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return this.file.ReadFile(buffer, offset, count);
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            return this.file.Seek(offset, origin);
        }

        public override void SetLength(long value)
        {
            throw new NotImplementedException();
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new NotImplementedException();
        }

        public override bool CanRead
        {
            get
            {
                return (this.file.FileAccess & FileAccess.Read) == FileAccess.Read; // ((this.file.FileAccess & ((FileAccess)(-2147483648))) == ((FileAccess)(-2147483648)));
            }
        }

        public override bool CanSeek
        {
            get
            {
                return true;
            }
        }

        public override bool CanWrite
        {
            get
            {
                return ((this.file.FileAccess & FileAccess.Write) == FileAccess.Write);
            }
        }

        public override long Length
        {
            get
            {
                return this.file.Length;
            }
        }

        public override long Position
        {
            get
            {
                return this.file.Position;
            }
            set
            {
                this.Seek(value, SeekOrigin.Begin);
            }
        }
    }
}

